/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jili.ubert;

import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.avis.client.Elvin;
import org.avis.client.NotificationListener;
import org.avis.client.Subscription;
import org.avis.common.InvalidURIException;

/**
 *
 * @author ChengJiLi
 */
public class SimulationExchangeServer {

    /**
     * @param args the command line arguments
     */
    /*
    public static HashMap<String,NewOrder> OrderQuene= new HashMap();
    public static Hash
    */
    private static final Log log = LogFactory.getLog(SimulationExchangeServer.class);
    public static void main(String[] args) {
        // TODO code application logic here
        /*
        1.args[1]传入配置文件SimulationExchangeServer.xml
        2.分regionID处理登记
        */
        String regionID = "C";
        String elvenIP = "localhost";
        String elvenPort = "";
        int simtype = 1;
        ResourceManager rm = new ResourceManager();
        String elvinUri = System.getProperty ("elvin", "elvin://"+elvenIP);
        try{
            Elvin elvin = new Elvin(elvinUri);
            log.info("启动连接avis router:"+elvinUri);
            //System.out.println("启动连接avis router:"+elvinUri);
            elvin.closeOnExit();
            final Subscription priceSubscription = elvin.subscribe ("Title == 'Price'");
    //        final Subscription priceSubscription = elvin.subscribe ("Title == 'Price' && RegionID == '"+regionID+"'");
            NotificationListener priceListener = new AcceptPrice(regionID);
            priceSubscription.addListener(priceListener);
            final Subscription orderSubscription = elvin.subscribe ("Title == 'Trade' && PipID == 0");
            NotificationListener orderListener = new AcceptOrder(simtype);
            orderSubscription.addListener(orderListener);
        }
        catch(InvalidURIException | IllegalArgumentException | IOException e){
            log.info(e);
        }
    }
    
}
